package com.owen.server.impl;

import com.owen.dao.FenleiDao;
import com.owen.pojo.Fenlei;
import com.owen.server.FenleiServer;
import com.owen.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FenleiServerImpl implements FenleiServer {

    @Autowired
    private FenleiDao fenleiDao;

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<Fenlei> findFenlei() {
        List<Fenlei> findFenlei = (List<Fenlei>) redisUtil.get("findFenlei");
        if (findFenlei == null) {
            findFenlei = fenleiDao.findFenlei();
            redisUtil.set("findFenlei", findFenlei);
        }
        return findFenlei;
    }

    public List<Fenlei> findByFenlei(Fenlei fenlei) {
        return fenleiDao.findByFenlei(fenlei);
    }

    @Override
    public Fenlei findById(Long id) {
        return fenleiDao.findById(id);
    }

    @Override
    public Integer deleteById(Long id) {
        Integer integer = fenleiDao.deleteById(id);
        if (integer > 0) {
            redisUtil.del("findFenlei");
        }
        return integer;
    }

    @Override
    public Integer updateById(Fenlei fenlei) {
        Integer integer = fenleiDao.updateById(fenlei);
        if (integer > 0) {
            redisUtil.del("findFenlei");
        }
        return integer;
    }

    @Override
    public Integer addFenlei(Fenlei fenlei) {
        Integer integer = fenleiDao.addFenlei(fenlei);
        if (integer > 0) {
            redisUtil.del("findFenlei");
        }
        return integer;
    }

    @Override
    public Integer deleteBatch(Integer[] ids) {
        Integer integer = fenleiDao.deleteBatch(ids);
        redisUtil.del("findFenlei");
        return integer;
    }

    @Override
    public List<Fenlei> findCommodityFenlei(Integer id) {
        return fenleiDao.findCommodityFenlei(id);
    }
}
